<?php

class Solution_model extends CI_Model{

    public function __construct(){
        $this->load->database();
    }

    public function create($id_user,$id_task,$data){
        $this->db->insert('solution',array('fk_users' => $id_user, 'fk_tasks' => $id_task, 'data' => $data));
    }

    public function delete($id_user,$id_task){
        $this->db->delete('solution', array('fk_users' => $id_user, 'fk_tasks' => $id_task));
    }
    
     public function deleteAll($id_task){
        $this->db->delete('solution', array('fk_tasks' => $id_task));
    }

    public function get($id_user,$id_task){
        $res = $this->db->get_where('solution', array('fk_users' => $id_user, 'fk_tasks' => $id_task))->result();
        return $res[0];
    }

    public function edit($id_user,$id_task,$new_data){
        $this->db->update('solution',array('data' => $new_data),array('fk_users' => $id_user, 'fk_tasks' => $id_task));
    }
    
    public function createEdit($id_user, $id_task, $data) {
          $query = $this->db->query("
            INSERT INTO solution (fk_users, fk_tasks, data) 
            VALUES ($id_user, $id_task, '$data') 
            ON DUPLICATE KEY UPDATE data='$data'");
    }

}

?>